<template>
	<view class="app">
		<view class="list">
			<view class="title">{{detail.name}}</view>
			<view class="secTit">
				<image src='/static/images/dingdan.png'></image>
				<text>订单信息</text>
			</view>
			<view class="item">
				<view>简介:</view>
				<view>{{detail.synopsis}}</view>
			</view>
			
			<view class="item">
				<view>单号:</view>
				<view>{{detail.id}}</view>
			</view>
			<view class="item">
				<view>采购类型:</view>
				<view>标准采购</view>
			</view>
			<view class="item">
				<view>采购地址:</view>
				<view>{{detail.address}}</view>
			</view>
			<view class="item">
				<view>提报开始时间:</view>
				<view>{{detail.startTime}}</view>
			</view>
			<view class="item">
				<view>提报截止时间:</view>
				<view>{{detail.endTime}}</view>
			</view>
			<view class="item">
				<view>预计总额:</view>
				<view class="red">{{submitProdTotalAmount + completeProdTotalAmount}}元</view>
			</view>
		</view>
		<view class="list">
			<view class="secTit">
				<image src='/static/images/kehu.png'></image>
				<text >提报人({{submitCount}}/{{submitCount+notSubmitCount}})</text>
			</view>
			<view class="circle">
				<view @tap='goTB(2)'>
					<view>
						<arprogress :percent="percent"><text>{{submitCount}}人</text></arprogress>
					</view>
					<text>已提报</text>
				</view>
				<view @tap='goTB(3)'>
					<arprogress :percent="percent" activeColor="#ff9a34"><text>{{notSubmitCount}}人</text></arprogress>
					<text>未提报</text>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="secTit">
				<image src='/static/images/dingdan.png'></image>
				<text>提报商品</text>
			</view>
			<view class="circle">
				<view>
					<view>
						<arprogress :percent="percent"><text>{{ submitProdTotalAmount}}元</text></arprogress>
					</view>
					<text>已下单({{submitProdCount}})</text>
				</view>
				<view>
					<arprogress :percent="percent" activeColor="#ff9a34"><text>{{completeProdTotalAmount}}元</text></arprogress>
					<text>待下单({{submitCount}})</text>
				</view>
			</view>
		</view>
		<view class="footer">
			<view v-if="detail.status=='0' || detail.status=='1'" @tap='jiehsu'>结束提报</view>
			<view @tap='goDingdan'>查看订单</view>
			<view @tap='pay'>立即下单</view>
		</view>
		<!-- 选择订单进行查看 -->
		<uni-popup ref="popup" :animation="true" type="center" backgroundColor="#fff" :mask-click="false"
		>
			<view class="ddPopup">
				<view class="top">
					<text>选择需要查看的订单</text>
					<uni-icons @tap='closePopup' type="close" size="24" color="#9b9b9b"></uni-icons>
				</view>
				<view v-if="items.length!==0" class="uni-list">
					<radio-group @change="radioChange">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
							<view>
								<radio :value="item.orderNumber" :checked="index === current"   />
							</view>
							<view class="des">
								<view>
									<text>单号: {{item.orderNumber}}</text>
								</view>
								<view>
									<text>数量：{{item.productNums}}</text>
									<text>创建时间：{{item.createTime}}</text>
								</view>
							</view>
						</label>
					</radio-group>
				</view>
				<view class="empty" v-else>
					<view class="empty-icon">
						<image src="/static/images/icon/empty.png"></image>
					</view>
					<view class="empty-text">数据暂无</view>
				</view>
				<view v-if="items.length!==0" class="seleOk" @tap='seleOk'>确定</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var http = require("../../../utils/http.js");
	import arprogress from '../../components/ar-circle-progress/ar-circle-progress.vue'
	export default {
		components:{arprogress},
		data(){
			return {
				percent:55,
				id:null,
				detail:{},
				notSubmitCount:0,
				submitCount:0,
				completeProdCount: 0,
				completeProdTotalAmount: 0,
				submitProdCount: 0,
				submitProdTotalAmount: 0,
				items:[],
				viewId:'',
				current: 0,
			}
		},
		onLoad(option){
			//获取订单信息
			this.id=option.id
			this.getInfo()
			//获取提报人先洗数据
			this.getTb()
			// 获取提报商品
			this.getTbSp()
		},
		
		methods:{
			//结束提报
			jiehsu(){
				var param = {
					url: "/p/cp/completeCP/"+this.id,
					method: "put",
					data: {
					},
					callBack: res => {
						uni.showToast({
							title:res,
							icon:'none'
						})
						setTimeout(function(){
							var pages = getCurrentPages(); //当前页面
							var prevPage = pages[pages.length - 2]; //上一页面
							prevPage.shouji = true
							//返回
							uni.navigateBack({
								delta: 1
							});
						},1000)
					}
				};
				http.request(param);
			},
			//选择单号确认
			seleOk(){
				this.$refs.popup.close()
				if(this.viewId=='') return
				uni.navigateTo({
					url:'/packageUser/pages/order-detail/order-detail?orderNum='+this.viewId ,
				})
			},
			radioChange: function(evt) {
				console.log(evt)
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].orderNumber === evt.detail.value) {
						this.current = i;
						this.viewId=this.items[i].orderNumber
						console.log(this.viewId)
						break;
					}
				}
			},
			closePopup() {
				this.$refs.popup.close()
			},
			//查看订单
			goDingdan(){
				this.$refs.popup.open()
				var params = {
					url: "/p/cp/sp/cpOrderNum/" + this.id,
					method: "GET",
					data: {},
					callBack: res => {
						this.items=res
						this.viewId=this.items[0].orderNumber
					}
				};
				http.request(params);
			},
			//立即下单
			pay(){
				var param = {
					url: "/p/cp/order/submit",
					method: "post",
					data: {
						collaborativePurchaseId:this.id,
						uuid:uni.getStorageSync('uuid'),
						dvyType:"1"
					},
					callBack: res => {
						uni.navigateTo({
							url:`/packageProduct/pages/payWay/payWay?orderNumbers=${res.orderNumbers}&dvyType=1&isPurePoints=`
						})
					}
				};
				http.request(param);
			},
			getTbSp(){
				var param = {
					url: "/p/cp/cpProdInfoAndCount?cpId="+this.id,
					method: "GET",
					data: {},
					callBack: res => {
						this.completeProdCount=res.completeProdCount
						this.completeProdTotalAmount=res.completeProdTotalAmount
						this.submitProdCount=res.submitProdCount
						this.submitProdTotalAmount=res.submitProdTotalAmount
					}
				};
				http.request(param);
			},
			getTb(){
				var param = {
					url: "/p/cp/"+this.id+"/spInfoAndCount",
					method: "GET",
					data: {},
					callBack: res => {
						this.notSubmitCount=res.notSubmitCount
						this.submitCount=res.submitCount
					}
				};
				http.request(param);
			},
			//获取订单信息
			getInfo(){
				var param = {
					url: "/p/cp/info/"+this.id,
					method: "GET",
					data: {},
					callBack: res => {
						this.detail=res
						console.log(this.detail.status=='2')
					}
				};
				http.request(param);
			},
			goTB(index){
				uni.navigateTo({
					url:`../tbList/index?index=${index}&id=${this.id}`
				})
			}
		}
	}
</script>

<style lang='scss'>
	view,text {
			box-sizing: border-box;
			line-height: 1;
			color:#333;
	}
	/* 列表为空 */
	.empty {
	  padding-top: 100rpx;
	  text-align: cneter;
	}
	.empty-icon {
	  display: block;
	  width: 80rpx;
	  height: 80rpx;
	  margin: 0 auto;
	  margin-bottom: 20rpx;
	}
	.empty-icon > image {
	  display: block;
	  width: 100%;
	  height: 100%;
	}
	.empty-text {
	  font-size: 28rpx;
	  text-align: center;
	  color: #999;
	  line-height: 40rpx;
	}
	.more {
		text-align: center;
		margin-top: 28rpx;
		font-size: 28rpx;
		color: #9b9b9b;
		padding: 20rpx;
	}
	.ddPopup {
		line-height: 1;
		box-sizing: border-box;
		padding: 20rpx 30rpx;
		width: 690rpx;
		height: auto;
		border-radius: 18rpx;
		.seleOk {
			width: 120rpx;
			height: 70rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color:#fff;
			background-color: #e43230;
			float: right;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
		}
		.top {
			display: flex;
			justify-content: space-between;
			height: 40rpx;
			align-items: center;
			margin-bottom: 20rpx;
			text {
				font-size: 32rpx;
				font-weight: bold;
			}
		}
		.uni-list {
			height: 400rpx;
			overflow: scroll;
			overflow-x: hidden;
			
		}
		.uni-list::-webkit-scrollbar{
		  display: none;
		}
		.uni-list-cell-pd {
			
			width: 600rpx;
			display: flex;
			padding: 20rpx;
			.des {
				display: flex;
				flex-direction: column;
				margin-left: 15rpx;
				view {
					margin-bottom: 20rpx;
					text {
						margin-right: 40rpx;
						font-size: 28rpx;
						color:#9b9b9b;
					}
				}
			}
		}
	}
	
	.footer {
		width: 100%;
		padding: 20rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background-color: #fff;
		view {
			border: 1rpx solid #e43320;
			border-radius: 15rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #e43320;
			font-size: 30rpx;
			width: 230rpx;
		}
		view:last-child {
			background-color: #e43320;
			color: #fff;
			font-weight: bold;
		}
	}
	.circle {
		display: flex;
		padding: 20rpx;
		background-color: #fff;
		>view {
			flex: 375rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			text {
				font-size: 28rpx;
				color: #9b9b9b;
				margin-top: 30rpx;
			}
			>view {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 375rpx;
				border-right: 1rpx solid #f4f4f4;
			}
		}
		>view:last-child{
			>view {
				border: none;
			}
		}
	}
	.list {
		padding: 20rpx 0;
		padding-top: 0;
		background-color: #f4f4f4;
		width: 100vw;
		.title {
			width: 100%;
			height: 80rpx;
			background-color: #fff;
			margin-bottom: 20rpx;
			font-size: 32rpx;
			font-weight: bold;
			padding-left: 30rpx;
			display: flex;
			align-items: center;
		}
		.secTit {
			border-bottom: 1rpx solid  #f4f4f4;
			height: 80rpx;
			display: flex;
			align-items: center;
			background-color: #fff;
			width: 100%;
			image {
				width: 45rpx;
				height: 40rpx;
				margin-right: 15rpx;
				margin-left: 30rpx;
			}
			text {
				font-size: 32rpx;
				color:#333;
			}
		}
	}
	.sec {
		font-weight: bold;
		margin: 40rpx 0;
		margin-left: 30rpx;
	}
	.item {
		background-color: #fff;
		margin-bottom: 25rpx;
		display: flex;
		width: 750rpx;
		margin: 0 auto;
		height: 60rpx;
		align-items: center;
		padding: 0 30rpx;
		view:first-child {
			margin-right: auto;
			color:#9b9b9b ;
		}
		
		view:nth-child(2){
			color: #333;
		}
		.red {
			color: #e43320 !important;
		}
	}
</style>
